package com.portal.util;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

public class HTTPUtil {
    public static String doPostStr(String url, String outStr){
        CloseableHttpClient httpClient= HttpClientBuilder.create().build();
        HttpPost httpPost=new HttpPost(url);
        String result = null;
        try {
            httpPost.setEntity(new StringEntity(outStr,"UTF-8"));
            HttpResponse response = httpClient.execute(httpPost);
            result = EntityUtils.toString(response.getEntity(), "UTF-8") ;

        } catch (IOException e) {
            e.printStackTrace();
        }
        return  result;
    }
}
